﻿using System;
using System.Collections.Generic;
using EZCRS.HCMS.DataAcl;
using System.Configuration;
using System.Collections;
using System.Text;
using System.Data;
using EZCRS.HCMS.Bll.AIR;
using EZCRS.HCMS.Entity;
using EZCRS.HCMS.Bll;


namespace EZCRS.HCMS.myajax
{
    public class BookLog : MainBase
    {
        ArrayList arrRecord;
        //记录数量
        int iRecordCount = 0;
        //总页数
        int iPageCount = 0;

        /// <summary>
        /// 酒店或集团预订记录
        /// </summary>
        /// <param name="cpage"></param>
        /// <param name="search"></param>
        /// <returns></returns>
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public ArrayList BookRecord(int cpage, string search, string orderkey)
        {
            #region
            arrRecord = new ArrayList();

            string gid = BasGroupId.ToString();
            string hid = BasHotelId.ToString();
            

            string orders = " updatetime desc";
            switch (orderkey)
            {
                case "1":
                    orders = " updatetime desc";
                    break;
                case "11":
                    orders = " updatetime ";
                    break;
                case "2":
                    orders = " nights desc";
                    break;
                case "22":
                    orders = " nights ";
                    break;
                case "3":
                    orders = " room desc";
                    break;
                case "33":
                    orders = " room ";
                    break;
                case "4":
                    orders = "username ";
                    break;
                case "44":
                    orders = "username desc";
                    break;
            }

            int pageindex = Convert.ToInt32(cpage);
            DataSet ds = null;

            
           ds = new BllBookLogView().GetBookLog(search, pageindex, orders);
            

            if (ds == null)
            {
                arrRecord.Add(EZCRS.HCMS.myajax.Site.StrError);
                return arrRecord;
            }


            DataTable dt = ds.Tables[0];
            iRecordCount = Convert.ToInt32(ds.Tables[1].Rows[0][0].ToString());

            iPageCount = (iRecordCount / EZCRS.HCMS.Bll.CFun.PageSize);
            if (iRecordCount % EZCRS.HCMS.Bll.CFun.PageSize > 0)
            {
                iPageCount++;
            }

            //组合字符串

            StringBuilder strTable = new StringBuilder();
            #region
            strTable.Append("<table id=\"tlist\" border=\"0\" cellpadding=\"1\" cellspacing=\"1\" width=\"100%\"><tr class=\"title1\" height=\"26\"><td width=\"6%\" style=\"color: white;\">" + EZCRS.HCMS.myajax.Site.StrNumb + "</td><td width=\"10%\" style=\"color: white;cursor:hand;\" onclick=\"javascript:setorders('4');\" title=\"" + EZCRS.HCMS.myajax.Site.StrKeyRank + "\">" + EZCRS.HCMS.myajax.Site.StrUserName + "</td><td width=\"10%\" style=\"color: white;\">" + EZCRS.HCMS.myajax.Site.StrTrueName + "</td><td width=\"20%\" style=\"color: white;\">" + EZCRS.HCMS.myajax.Site.StrHotelName + "</td><td width=\"12%\" style=\"color: white;cursor:hand;\" onclick=\"javascript:setorders('1');\"  title=\"" + EZCRS.HCMS.myajax.Site.StrKeyRank + "\">" + EZCRS.HCMS.myajax.Site.StrCheckin + "</td><td width=\"6%\" style=\"color: white;cursor:hand;\" onclick=\"javascript:setorders('2');\"  title=\"" + EZCRS.HCMS.myajax.Site.StrKeyRank + "\">" + EZCRS.HCMS.myajax.Site.StrNeight + "</td><td width=\"6%\" style=\"color: white;cursor:hand;\" onclick=\"javascript:setorders('3');\"  title=\"" + EZCRS.HCMS.myajax.Site.StrKeyRank + "\">" + EZCRS.HCMS.myajax.Site.StrRoom + "</td><td width=\"8%\" style=\"color: white;\">" + EZCRS.HCMS.myajax.Site.StrConfm + "</td><td width=\"8%\" style=\"color: white;\">修改</td></tr>");
            if (ds.Tables[0].Rows.Count > 0)
            {
                for (int row = 0; row < dt.Rows.Count; row++)
                {
                    strTable.Append("<tr");
                    if (row % 2 == 0)
                    {
                        strTable.Append(" class='line-odd'");
                    }
                    else
                    {
                        strTable.Append(" class='line-even'");
                    }
                    strTable.Append(" onmouseover=\"currentcolor=this.style.backgroundColor;this.style.backgroundColor='#B9CEEA';\"");
                    strTable.Append(" onmouseout=\"this.style.backgroundColor=currentcolor;\"");
                    strTable.Append(">");
                    string sNo = "";
                    if (((pageindex - 1) * EZCRS.HCMS.Bll.CFun.PageSize + row + 1) < 10)
                    {
                        sNo = "0" + Convert.ToString(row + 1);
                    }
                    else
                    {
                        sNo = Convert.ToString((pageindex - 1) * EZCRS.HCMS.Bll.CFun.PageSize + row + 1);
                    }
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(sNo.ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["userid"].ToString());
                    strTable.Append("</div></td>");

                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["guestlastname"].ToString() +" "+ ds.Tables[0].Rows[row]["guestfirstname"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["title"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["updatetime"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["nights"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["rooms"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\">");
                    strTable.Append(ds.Tables[0].Rows[row]["confnum"].ToString());
                    strTable.Append("</div></td>");
                    strTable.Append("<td><div align=\"center\"><a href=\"bookingdetail1.aspx?id=" + ds.Tables[0].Rows[row]["id"].ToString() + "\" target=\"_blank\">处理</a></div></td>");
                    strTable.Append("</tr>");
                }
            }
            else
            {
                strTable.Append("<tr height=\"35\" class=\"line-odd\"><td colspan=\"9\" align=\"center\">" + EZCRS.HCMS.myajax.Site.StrNonData + "</td></tr>");
            }
            strTable.Append("</table>");
            #endregion
            //将表格放入arraylist
            arrRecord.Add(strTable.ToString());
            //将总页数放入arraylist
            arrRecord.Add(iPageCount.ToString() == "0" ? "1" : iPageCount.ToString());
            //将总记录数放入arraylist
            arrRecord.Add(iRecordCount.ToString());

            return arrRecord;
            #endregion
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string SaveComment(string detail,string verifycode)
        {
                Hcrs_CCComment comment = new Hcrs_CCComment();
                comment.indetail = detail;
                comment.inname = base.BasUserName;
                comment.verifycode = verifycode;
                comment.intype = 0;
                if (new BllHcrs_CCComment().InsertorUpdateitem(comment))
                {
                    return "1";
                }
                else
                {
                    return "0";
                }
            
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string SaveRoomDay(string roomList, string bookStatus,string verifyCode)
        {
            if (bookStatus == "4")
            {
                new BllBookLogView().CancelBooklog(verifyCode);
            }

            if (new BllHcrs_resvlog().SaveGetStatus(Convert.ToInt32(bookStatus), verifyCode))
            {
                if (new BllHcrs_CCDayRoom().InsertOrUpdateItem(roomList, verifyCode))
                {
                    return "1";
                }
                else
                {
                    return "2";
                }
            }
            else
            {
                return "0";
            }
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public string SaveNewConfnum(string newConfnum,  string verifyCode)
        {
            newConfnum = EZCRS.HCMS.Bll.CFun.VerifySQL(newConfnum);
            verifyCode = EZCRS.HCMS.Bll.CFun.VerifySQL(verifyCode);
            if (new BllHcrs_resvlog().SaveConfnum(newConfnum, verifyCode))
            {
                return "1";
            }
            else
            {
                return "0";
            }
        }
    }
}
